import { limitContinuousLettersOrNumbers } from '@/utils/rule'
import * as mars3d from 'mars3d'
import * as Cesium from 'mars3d-cesium'
import WKT from 'terraformer-wkt-parser'
// @ts-ignore
import $ from 'jquery'
// 根据用户偏好设置图层
const getUserPreferencesLayers = (baseMapName: any, noteName: any) => {
     const baseMaps: any = {
          天地图影像: {
               name: '底图',
               type: 'tdt',
               layer: 'img_d',
               pid: 1,
               id: 2,
               zIndex: 2,
          },
          ArcGIS影像: {
               pid: 10,
               name: 'ArcGIS影像',
               icon: 'http://mars3d.cn/img/basemaps/esriWorldImagery.png',
               type: 'xyz',
               url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
               enablePickFeatures: false,
               id: 21,
               templateValues: {
                    dataServer: '//data.mars3d.cn',
                    gltfServerUrl: '//data.mars3d.cn/gltf',
               },
               opacity: 1,
               zIndex: 15,
          },
          星图影像: {
               name: '底图',
               type: 'xyz',
               url: 'https://tiles{s}.geovisearth.com/base/v1/img/{z}/{x}/{y}?token=82455ef06c72bb3a35bbb4d7d05fd9eceb96a94dc942a056b8feb0e5928ed96f',
               subdomains: '123',
          },
          微软影像: {
               pid: 10,
               name: '微软影像',
               icon: 'http://mars3d.cn/img/basemaps/bingAerial.png',
               type: 'bing',
               layer: 'Aerial',
               id: 22,
               opacity: 1,
               zIndex: 16,
          },
          高德影像: {
               name: '底图',
               type: 'gaode',
               layer: 'img_d',
               pid: 7,
               id: 8,
               zIndex: 6,
          },
          百度影像: {
               name: '底图',
               type: 'baidu',
               layer: 'img_d',
               pid: 12,
               id: 13,
               zIndex: 9,
          },
          百度电子: {
               pid: 10,
               name: '百度电子',
               icon: 'http://mars3d.cn/img/basemaps/bd-vec.png',
               type: 'baidu',
               layer: 'vec',
               id: 15,
               opacity: 1,
               zIndex: 11,
          },
     }
     const noteMaps: any = {
          天地图注记: {
               name: '注记',
               type: 'tdt',
               layer: 'img_z',
               pid: 1,
               parent: {
                    pid: 10,
                    name: '天地图影像',
                    icon: 'http://mars3d.cn/img/basemaps/tdt_img.png',
                    type: 'group',
                    layers: [
                         {
                              name: '底图',
                              type: 'tdt',
                              layer: 'img_d',
                              pid: 1,
                              id: 2,
                              zIndex: 2,
                         },
                         {
                              name: '注记',
                              type: 'tdt',
                              layer: 'img_z',
                              pid: 1,
                              id: 3,
                              zIndex: 3,
                         },
                    ],
                    id: 1,
               },
               id: 3,
               zIndex: 3,
          },
          高德注记: {
               name: '注记',
               type: 'gaode',
               layer: 'img_z',
               pid: 7,
               parent: {
                    pid: 10,
                    name: '高德影像',
                    type: 'group',
                    icon: 'http://mars3d.cn/img/basemaps/gaode_img.png',
                    layers: [
                         {
                              name: '底图',
                              type: 'gaode',
                              layer: 'img_d',
                              pid: 7,
                              id: 8,
                              zIndex: 6,
                         },
                         {
                              name: '注记',
                              type: 'gaode',
                              layer: 'img_z',
                              pid: 7,
                              id: 9,
                              zIndex: 7,
                         },
                    ],
                    id: 7,
               },
               id: 9,
               zIndex: 7,
          },
     }
     return {
          baseMap: baseMaps[baseMapName],
          note: noteMaps[noteName],
     }
}
export default function (): any {
     const mapOptions = {
          scene: {
               center: {
                    lat: 33,
                    lng: 109,
                    alt: 1425760.8,
                    heading: 358.9,
                    pitch: -79.1,
               },
               sceneMode: 2,
          },
          terrain: {
               url: 'http://data.mars3d.cn/terrain',
               show: false,
          },
          basemaps: [
               {
                    pid: 10,
                    name: '天地图影像',
                    icon: 'http://mars3d.cn/img/basemaps/tdt_img.png',
                    type: 'group',
                    show: 'true',
                    layers: [
                         {
                              name: '底图',
                              type: 'tdt',
                              layer: 'img_d',
                              pid: 1,
                              parent: {
                                   pid: 10,
                                   name: '天地图影像',
                                   icon: 'http://mars3d.cn/img/basemaps/tdt_img.png',
                                   type: 'group',
                                   layers: [
                                        {
                                             name: '底图',
                                             type: 'tdt',
                                             layer: 'img_d',
                                             pid: 1,
                                             id: 2,
                                             zIndex: 2,
                                        },
                                        {
                                             name: '注记',
                                             type: 'tdt',
                                             layer: 'img_z',
                                             pid: 1,
                                             id: 3,
                                             zIndex: 3,
                                        },
                                   ],
                                   id: 1,
                              },
                              id: 2,
                              zIndex: 2,
                         },
                         {
                              name: '注记',
                              type: 'tdt',
                              layer: 'img_z',
                              pid: 1,
                              parent: {
                                   pid: 10,
                                   name: '天地图影像',
                                   icon: 'http://mars3d.cn/img/basemaps/tdt_img.png',
                                   type: 'group',
                                   layers: [
                                        {
                                             name: '底图',
                                             type: 'tdt',
                                             layer: 'img_d',
                                             pid: 1,
                                             id: 2,
                                             zIndex: 2,
                                        },
                                        {
                                             name: '注记',
                                             type: 'tdt',
                                             layer: 'img_z',
                                             pid: 1,
                                             id: 3,
                                             zIndex: 3,
                                        },
                                   ],
                                   id: 1,
                              },
                              id: 3,
                              zIndex: 3,
                         },
                    ],
                    id: 1,
                    opacity: 1,
               },
               {
                    pid: 10,
                    name: '天地图电子',
                    icon: 'http://mars3d.cn/img/basemaps/tdt_vec.png',
                    type: 'group',
                    layers: [
                         {
                              name: '底图',
                              type: 'tdt',
                              layer: 'vec_d',
                              pid: 4,
                              parent: {
                                   pid: 10,
                                   name: '天地图电子',
                                   icon: 'http://mars3d.cn/img/basemaps/tdt_vec.png',
                                   type: 'group',
                                   layers: [
                                        {
                                             name: '底图',
                                             type: 'tdt',
                                             layer: 'vec_d',
                                             pid: 4,
                                             id: 5,
                                             zIndex: 4,
                                        },
                                        {
                                             name: '注记',
                                             type: 'tdt',
                                             layer: 'vec_z',
                                             pid: 4,
                                             id: 6,
                                             zIndex: 5,
                                        },
                                   ],
                                   id: 4,
                              },
                              id: 5,
                              zIndex: 4,
                         },
                         {
                              name: '注记',
                              type: 'tdt',
                              layer: 'vec_z',
                              pid: 4,
                              parent: {
                                   pid: 10,
                                   name: '天地图电子',
                                   icon: 'http://mars3d.cn/img/basemaps/tdt_vec.png',
                                   type: 'group',
                                   layers: [
                                        {
                                             name: '底图',
                                             type: 'tdt',
                                             layer: 'vec_d',
                                             pid: 4,
                                             id: 5,
                                             zIndex: 4,
                                        },
                                        {
                                             name: '注记',
                                             type: 'tdt',
                                             layer: 'vec_z',
                                             pid: 4,
                                             id: 6,
                                             zIndex: 5,
                                        },
                                   ],
                                   id: 4,
                              },
                              id: 6,
                              zIndex: 5,
                         },
                    ],
                    id: 4,
                    opacity: 1,
               },
          ],
          layers: [],
          control: {
               baseLayerPicker: true,
               homeButton: true,
               sceneModePicker: false,
               vrButton: false,
               fullscreenButton: false,
               navigationHelpButton: false,
               animation: false,
               timeline: false,
               infoBox: false,
               geocoder: false,
               selectionIndicator: false,
               showRenderLoopErrors: true,
               contextmenu: { hasDefault: true },
               mouseDownView: true,
               zoom: { insertIndex: 1 },
               compass: { bottom: '200px', right: '5px' },
               distanceLegend: { left: '100px', bottom: '2px' },
               locationBar: {
                    crs: 'CGCS2000_GK_Zone_3',
                    crsDecimal: 0,
                    show: false,
                    template:
                         "<div>经度:{lng}</div> <div>纬度:{lat}</div>  <div>方向：{heading}°</div> <div>俯仰角：{pitch}°</div><div class='hide700'>视高：{cameraHeight}米</div>帧率：{fps}帧</div>",
               },
          },
     }
     const initMap = (dom: any, val = {}) => {
          let map: any = null
          const options: any = { ...mapOptions, ...val }
          map = new mars3d.Map(dom, options)
          return map
     }
     const animation = (mapData: any) => {
          mapData.openFlyAnimation({
               callback: function () {},
          })
     }
     const flyToLayer = (mapData: any, id: any) => {
          mapData.getLayer(id).flyTo()
     }
     //飞到指定位置
     const setPosition = (map: any, coord: any) => {
          let { lat, lng, alt } = coord
          if (alt === undefined) {
               alt = 100
          }
          const pos = { lat: lat, lng: lng, alt: alt }
          map.setCameraView(pos, {
               duration: 1.6,
          })
     }
     //飞到指定范围
     const FlytoRectangle = (map: any, west: any, south: any, east: any, north: any) => {
          const ext = mars3d.Cesium.Rectangle.fromDegrees(west, south, east, north)
          const op = {}
          map.flyToExtent(ext, op)
     }
     // 飞行到指定范围
     const mapFlytoExent = (map: any, extent: any) => {
          const exent = {
               xmin: Number(extent.xmin),
               xmax: Number(extent.xmax),
               ymin: Number(extent.ymin),
               ymax: Number(extent.ymax),
          }
          map.flyToExtent(exent, {})
     }
     // 根据geometry 获取指定类型 并移动到指定位置
     const getGemoToFly = (map: any, geometry: any) => {
          const features: any = typeof geometry == 'string' ? WKT.parse(geometry) : geometry
          if (features.type == 'Point') {
               const coord = {
                    lat: features.coordinates[1],
                    lng: features.coordinates[0],
               }
               setPosition(map, coord)
          } else if (features.type == 'LineString') {
               // 如果是三维数组 改成二维数组
               if (features.coordinates[0][0][0]) {
                    features.coordinates = features.coordinates.flat()
               }
               const mpt: any = mars3d.LngLatPoint.fromCartesian(mars3d.PolyUtil.centerOfMass(features.coordinates as any))
               console.log(mpt, features)
               const coord = {
                    lat: mpt.lat,
                    lng: mpt.lng,
               }
               setPosition(map, coord)
          }
     }
     const addRawLineFeature = (mapData: any, data: any, layerId: string) => {
          const graphicLayer = mapData.getLayerById(layerId)
          const arr = data.map((item: any) => {
               return {
                    features: WKT.parse(item.geom),
                    style: {},
                    label: item.xlmc,
               }
          })
          arr.forEach((item: any) => {
               const graphic = new mars3d.graphic.PolylineEntity({
                    positions: item.features.coordinates.flat(),
                    style: {
                         width: 4,
                         materialType: mars3d.MaterialType.PolylineDash,
                         hasShadows: true,
                         // addHeight: 20,
                         outlineColor: '#f17e00',
                         shadows: Cesium.ShadowMode.DISABLED,
                         materialOptions: {
                              color: '#f17e00',
                              gapColor: '#fff2ea',
                              dashLength: 50,
                              dashPower: 50,
                              dashPattern: parseInt('11111111000000', 2),
                         },
                         image: '//data.mars3d.cn/img/textures/line-gradient.png',
                         label: {
                              text: item.label.split('').join('\n'),
                              font_size: 25,
                              show: false,
                              color: '#fc07ff',
                              font_family: '仿宋', // 字体
                              font_weight: 'bold',
                              verticalOrigin: Cesium.HorizontalOrigin.CENTER,
                              // font_style: 'normal', // 字体样式
                              pixelOffsetX: 20,
                              pixelOffsetY: 0,
                              outline: true,
                              outlineColor: '#ccc',
                              outlineOpacity: 1,
                              outlineWidth: 2,
                              scaleByDistance: new Cesium.NearFarScalar(1.5e2, 1.0, 8.0e6, 0.1),
                              distanceDisplayCondition: true,
                              distanceDisplayCondition_far: 500000,
                              distanceDisplayCondition_near: 0,
                         },
                    },
                    name: item.label,
                    attr: { ...item },
               } as any)
               graphicLayer.addGraphic(graphic)
               // const labelArr = addSplitLabel(
               //      {
               //           positions: graphic.positionsShow,
               //           text: item.label,
               //           step: 200,
               //      },
               //      graphicLayer,
               // )
               // graphic.on(mars3d.EventType.clusterItemChange, function (e) {
               //      labelArr.forEach((label: any) => {
               //           label.isCluster = e.graphic.isCluster
               //      })
               // })
          })
     }
     // 添加千米表矢量
     const addKmFeature = (mapData: any, kmlList: any, layerId: string) => {
          const KLMTLayers = mapData.getLayerById(layerId)
          const labelList: any = []
          kmlList.forEach((item: any) => {
               const graphic = new mars3d.graphic.LabelPrimitive({
                    position: [item.lon, item.lat],

                    style: {
                         text: item.notes,
                         font_size: 30,
                         color: '#bb1e3f',
                         distanceDisplayCondition: true,
                         distanceDisplayCondition_far: 50000,
                         horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                         scaleByDistance: new Cesium.NearFarScalar(10000, 0.5, 500000, 0.1),
                         background: true,
                         backgroundColor: 'rgba(255,255,255,0.8)',
                         stroke: true,
                         strokeColor: 'rgba(0,0,0,0.5)',
                         backgroundPadding: 10,
                         // clampToGround: true
                    },
                    // clampToTileset: true,
                    frameRateHeight: 30,
               })
               labelList.push(graphic)
          })
          KLMTLayers.addGraphic(labelList)
     }
     // 添加矢量图层
     const addFeatureLayers = (map: any, layers: any, isPopup?: boolean) => {
          layers.forEach((item: any) => {
               const featureLayer = new mars3d.layer.GraphicLayer({
                    id: item,
                    show: true,
                    type: 'graphic',
               } as any)
               map.addLayer(featureLayer)
               if (!isPopup) return
               featureLayer.bindTooltip(
                    (event: any) => {
                         const attr = event.graphic.attr || {}
                         const { colnames, data, labelText } = attr
                         if (!colnames || !data) {
                              return ''
                         }
                         const content = Object.entries(colnames)
                              .map(
                                   ([key, value]) => `
                            <div class="data-li">
                                <div class="data-label">${value}：</div>
                                <div class="data-value">
                                    <span id="lablLiuliang" class="label-num">${data[key]}</span>
                                    <span class="label-unit"></span>
                                </div>
                            </div>
                        `,
                              )
                              .join('')

                         const html = `
                    <div class="marsTiltPanel marsTiltPanel-theme-blue">
                        <div class="marsTiltPanel-wrap">
                            <div class="area">
                                <div class="arrow-lt"></div>
                                <div class="b-t"></div>
                                <div class="b-r"></div>
                                <div class="b-b"></div>
                                <div class="b-l"></div>
                                <div class="arrow-rb"></div>
                                <div class="label-wrap">
                                    <div class="title">${labelText}</div>
                                    <div class="label-content">
                                        ${content}
                                    </div>
                                </div>
                            </div>
                            <div class="b-t-l"></div>
                            <div class="b-b-r"></div>
                        </div>
                        <div class="arrow"></div>
                    </div>
                `

                         return html
                    },
                    {
                         template: false,
                         direction: 'right',
                         offsetX: 135,
                         offsetY: 0,
                    },
               )
          })
     }
     // 新增点
     const addPointFeature = (position: any, featureData: any, layersId: string) => {
          let graphic = null
          graphic = new mars3d.graphic.BillboardEntity({
               position: position,
               style: {
                    image: `./img/mapImg/${layersId}.png`,
                    scale: 0.2,
                    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    // addHeight: 20,
                    distanceDisplayCondition: true,
                    distanceDisplayCondition_far: 8000,
                    pixelOffsetY: -12,
                    flyTo: true,
                    label: {
                         text: featureData.describe ?? '',
                         font_size: 16,
                         background: true, // 是否开启背景
                         backgroundColor: 'rgba(2, 46, 87,0.5)', // 背景颜色
                         backgroundPadding: 8,
                         font_weight: 'bold',
                         color: '#ffffff',
                         pixelOffsetY: 10,
                         distanceDisplayCondition: true,
                         distanceDisplayCondition_far: 8000,
                         distanceDisplayCondition_near: 0,
                    },
               },
               attr: {
                    data: featureData,
               },
               name: featureData.xlname,
          } as any)
          return graphic
     }
     // 添加自定义工具
     const addToolButton = (map: any, callback: any) => {
          const toolButton = new mars3d.control.ToolButton({
               title: '里程导航',
               icon: 'img/map/mileageNavigation.png',
               className: '',
               insertIndex: 1, // 插入的位置顺序, 1是home按钮后面
               click: () => {
                    callback()
               },
          })
          map.addControl(toolButton)
     }
     // 地图绑定鼠标悬浮事件
     const bindMapHover = (map: any, callback: any) => {
          let timer: any = null
          map &&
               map.on('mouseMoveTarget', async (data: any) => {
                    const coord: any = mars3d.PointTrans.cartesian2lonlat(data.cartesian)
                    const obj = {
                         lon: coord[0] ?? 0,
                         lat: coord[1] ?? 0,
                    }
                    if (timer) {
                         clearTimeout(timer)
                    }
                    timer = setTimeout(() => {
                         callback(obj)
                    }, 1000)
               })
     }
     const setLocationOption = (map: any, val: any) => {
          const options = {
               crs: 'CGCS2000_GK_Zone_3',
               crsDecimal: 0,
               template: `<div>${val}</div> <div>经度:{lng}</div> <div>纬度:{lat}</div> <div class='hide1000'>横{crsx}  纵{crsy}</div> <div>海拔：{alt}米</div> <div class='hide700'>层级：{level}</div><div>方向：{heading}°</div> <div>俯仰角：{pitch}°</div><div class='hide700'>视高：{cameraHeight}米</div>帧率：{fps}帧</div>`,
          }
          map.controls.locationBar.setOptions({
               ...options,
          })
     }
     //加载铁路线位服务——除北京高铁
     const AddSuperMapRailLayer = async (
          _serviceUrl: string,
          token?: string,
          tempLayerId?: string,
          filters?: any,
          extent_?: any,
          map?: any, //地图对象
     ) => {
          //0.首先判断当前的临时图层ID是否可用，如果不可用，则根据filter创建临时图层,先不考虑这个
          if (!tempLayerId) {
               //1.创建//1.创建Templayer
               const createTemplayerUrl = `${_serviceUrl}/tempLayersSet.json?token=${token}`
               //2.更新fiter
               //2.1.获取newResourceID
               let newResourceID: any
               $.ajax({
                    type: 'POST',
                    url: createTemplayerUrl,
                    contentType: 'application/x-www-form-urlencoded',
                    async: false,
                    success: function (res: any) {
                         //console.log(res, '???ss')
                         if (res && res.succeed) {
                              newResourceID = res.newResourceID //获取资源id，然后开始创建 -全部线路
                              // console.log(filters, '临时???ss-2', newResourceID)
                         }
                    },
                    error: function (err: any) {
                         console.log(JSON.stringify(err))
                    },
               })

               if (!newResourceID) return null

               if (filters) {
                    const layerStatuses = []
                    for (const ele in filters) {
                         const layerStatus = {
                              type: 'UGC',
                              name: ele,
                              visible: true,
                              displayFilter: filters[ele],
                         }
                         layerStatuses.push(layerStatus)
                    }
                    const layerparms = [
                         {
                              subLayers: {
                                   layers: layerStatuses,
                              },
                         },
                    ]
                    const updateTemplayerUrl = `${_serviceUrl}/tempLayersSet/${newResourceID}.json?elementRemain=true&reference=${newResourceID}&token=${token}&_method=PUT`
                    //console.log(updateTemplayerUrl, '???ss-2')
                    $.ajax({
                         type: 'POST',
                         url: updateTemplayerUrl,
                         contentType: 'application/json',
                         async: false,
                         data: JSON.stringify(layerparms),
                         success: function (res: any) {
                              if (res && res.succeed) {
                                   //console.log(filters, '???ss-2', newResourceID)
                                   tempLayerId = newResourceID
                              }
                         },
                         error: function (err: any) {
                              tempLayerId = undefined
                              //console.log(JSON.stringify(err), '???ss-2')
                         },
                    })
               }
               if (!tempLayerId) return null
          }
          _serviceUrl = _serviceUrl + '/zxyTileImage/{z}/{x}/{y}.png?transparent=true&layersID=' + tempLayerId + '&token=' + token
          const layer_ = new mars3d.layer.XyzLayer({
               id: '铁路线位',
               url: _serviceUrl,
               zIndex: 10,
               rectangle: extent_,
          })
          map.addLayer(layer_)
     }
     const addRoamGraphic = (map: any, layersId: string, position: any, name: string) => {
          const graphicLayer = map.getLayerById(layersId)
          position = position.map((item: any) => {
               return [...item, 0]
          })

          const fixedRoute = new mars3d.graphic.FixedRoute({
               name: name,
               id: layersId,
               speed: 30,
               positions: position,
               clockLoop: true, // 是否循环播放
               clampToTileset: true,
               flyTo: true,
               camera: {
                    pitch: -30,
                    radius: 500,
               },
               model: {
                    url: '//data.mars3d.cn/gltf/mars/man/walk.gltf',
                    scale: 5,
                    minimumPixelSize: 50,
                    clampToGround: true,
               },
               polyline: {
                    width: 5,
                    // 动画线材质
                    materialType: mars3d.MaterialType.LineFlow,
                    materialOptions: {
                         color: Cesium.Color.AQUA,
                         image: '//data.mars3d.cn/img/textures/arrow-small.png',
                         repeat: new Cesium.Cartesian2(200, 1),
                         speed: 2,
                         bgColor: '#0000ff',
                    },
                    clampToGround: true,
                    showAll: true,
               },
               path: {
                    color: 'rgba(255,255,0,1.0)',
                    width: 2,
                    leadTime: 0,
                    clampToGround: true,
                    zIndex: 8,
               },
          })
          graphicLayer.addGraphic(fixedRoute)

          // 绑定popup
          bindRoamPopup(map, fixedRoute)

          fixedRoute.on(mars3d.EventType.start, function (event) {
               console.log('漫游开始start')
          })
          fixedRoute.on(mars3d.EventType.end, function (event) {
               console.log('漫游结束end')
          })
          // ui面板信息展示
          fixedRoute.on(
               mars3d.EventType.change,
               mars3d.Util.funThrottle((event) => {
                    // 取实时信息，可以通过  fixedRoute.info
                    // eventTarget.fire('roamLineChange', event)
               }, 500),
          )

          // fixedRoute.autoSurfaceHeight({ exact: true }).then(function (e) {
          // 不贴地时，直接开始
          fixedRoute.start()
          fixedRoute.openPopup() // 显示popup
          // })
     }
     const bindRoamPopup = (map: any, fixedRoute: any) => {
          fixedRoute.bindPopup(
               `<div style="width: 200px">
      <div>总 距 离：<span id="lblAllLen"> </span></div>
      <div>剩余距离：<span id="lblRemainLen"> </span></div>
    </div>`,
               { closeOnClick: false },
          )

          // 刷新局部DOM,不影响popup面板的其他控件操作
          fixedRoute.on(mars3d.EventType.popupRender, function (event: any) {
               const container = event.container // popup对应的DOM

               const params = fixedRoute?.info
               if (!params) {
                    return
               }

               const lblAllLen = container.querySelector('#lblAllLen')
               if (lblAllLen) {
                    lblAllLen.innerHTML = mars3d.MeasureUtil.formatDistance(params.distance_all)
               }

               const lblAllTime = container.querySelector('#lblAllTime')
               if (lblAllTime) {
                    lblAllTime.innerHTML = mars3d.Util.formatTime(params.second_all / map.clock.multiplier)
               }

               const lblStartTime = container.querySelector('#lblStartTime')
               if (lblStartTime) {
                    lblStartTime.innerHTML = mars3d.Util.formatDate(Cesium.JulianDate.toDate(fixedRoute.startTime), 'yyyy-M-d HH:mm:ss')
               }

               const lblRemainTime = container.querySelector('#lblRemainTime')
               if (lblRemainTime) {
                    lblRemainTime.innerHTML = mars3d.Util.formatTime((params.second_all - params.second) / map.clock.multiplier)
               }

               const lblRemainLen = container.querySelector('#lblRemainLen')
               if (lblRemainLen) {
                    lblRemainLen.innerHTML = mars3d.MeasureUtil.formatDistance(params.distance_all - params.distance) || '完成'
               }
          })
     }
     const addPointGraphic = (map: any, layersId: any, position: any, attr: any, name: string) => {
          const graphicLayer = map.getLayerById(layersId)
          const graphic = new mars3d.graphic.PointPrimitive({
               position: position,
               name: name,
               style: {
                    color: 'red',
                    pixelSize: 6,
                    outlineColor: 'red',
                    outlineWidth: 1,
                    zIndex: 9,
               },

               attr: { ...attr },
          })

          const inthtml = `<table style="width: auto; padding: 0px;border-radio: 0px; border: 0px; ">
            <tr>
              <td>时间：</td>
              <td>${attr.ptime}</td>
            </tr>
          </table>`
          graphic.bindTooltip(inthtml)
          graphicLayer.addGraphic(graphic)
     }
     return {
          mapOptions,
          animation,
          initMap,
          flyToLayer,
          setPosition,
          FlytoRectangle,
          mapFlytoExent,
          getUserPreferencesLayers,
          addRawLineFeature,
          getGemoToFly,
          addKmFeature,
          addFeatureLayers,
          addToolButton,
          setLocationOption,
          bindMapHover,
          AddSuperMapRailLayer,
          addPointFeature,
          addRoamGraphic,
          addPointGraphic,
     }
}
